/***********************************************************************************************************************************
 * Name:	Invalid-DefaultDB.sql
 * Author:	Frank Figearo (frank.figearo@us.bbaaviation.com|frank@sqlnerd.me)
 * Summary:	List logins specifying a default database that doesn't exist.
 */
SET IMPLICIT_TRANSACTIONS OFF; IF 0 < @@TRANCOUNT ROLLBACK;
GO
SELECT sp.name, sp.default_database_name
  FROM sys.server_principals sp
  LEFT JOIN sys.databases d ON (sp.default_database_name = d.name)
  WHERE sp.[type] IN ('G','S','U')
	AND d.database_id IS NULL;
GO